# -*- encoding:utf-8 -*-
from mako import runtime, filters, cache
UNDEFINED = runtime.UNDEFINED
__M_dict_builtin = dict
__M_locals_builtin = locals
_magic_number = 5
_modified_time = 1292135971.7651999
_template_filename=u'/Users/joeldunham/old/onlinelinguisticdatabase/templates/base/collectionViews.html'
_template_uri=u'/base/collectionViews.html'
_template_cache=cache.Cache(__name__, _modified_time)
_source_encoding='utf-8'
from webhelpers.html import escape
_exports = ['collectionViewPaper', 'displayCollectionDataAndButtons', 'displayFormsAsColumns', 'displayForm', 'displayCollectionData', 'displayContent', 'displayCollectionButtons', 'collectionViewReallyShort', 'displayContentMin', 'collectionViewLong', 'collectionViewShort', 'displayContentEmbedded']


# SOURCE LINE 6
import re 

def _mako_get_namespace(context, name):
    try:
        return context.namespaces[(__name__, name)]
    except KeyError:
        _mako_generate_namespaces(context)
        return context.namespaces[(__name__, name)]
def _mako_generate_namespaces(context):
    # SOURCE LINE 3
    ns = runtime.Namespace(u'markup', context._clean_inheritance_tokens(), templateuri=u'/base/markup.html', callables=None, calling_uri=_template_uri, module=None)
    context.namespaces[(__name__, u'markup')] = ns

    # SOURCE LINE 4
    ns = runtime.Namespace(u'javascriptDefs', context._clean_inheritance_tokens(), templateuri=u'/base/javascriptDefs.html', callables=None, calling_uri=_template_uri, module=None)
    context.namespaces[(__name__, u'javascriptDefs')] = ns

    # SOURCE LINE 1
    ns = runtime.Namespace(u'fileViews', context._clean_inheritance_tokens(), templateuri=u'/base/fileViews.html', callables=None, calling_uri=_template_uri, module=None)
    context.namespaces[(__name__, u'fileViews')] = ns

    # SOURCE LINE 2
    ns = runtime.Namespace(u'formViews', context._clean_inheritance_tokens(), templateuri=u'/base/formViews.html', callables=None, calling_uri=_template_uri, module=None)
    context.namespaces[(__name__, u'formViews')] = ns

def render_body(context,**pageargs):
    context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        _import_ns = {}
        _mako_get_namespace(context, u'markup')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'javascriptDefs')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'fileViews')._populate(_import_ns, [u'displayFile', u'displayAudio'])
        _mako_get_namespace(context, u'formViews')._populate(_import_ns, [u'formViewLong', u'formViewForAssociation', u'displayAssociatedFiles', u'formViewForMemory'])
        __M_writer = context.writer()
        # SOURCE LINE 1
        __M_writer(u'\n')
        # SOURCE LINE 2
        __M_writer(u'\n')
        # SOURCE LINE 3
        __M_writer(u'\n')
        # SOURCE LINE 4
        __M_writer(u'\n\n')
        # SOURCE LINE 6
        __M_writer(u'\n\n')
        # SOURCE LINE 30
        __M_writer(u'\n\n')
        # SOURCE LINE 34
        __M_writer(u'\n\n\n')
        # SOURCE LINE 40
        __M_writer(u'\n\n')
        # SOURCE LINE 120
        __M_writer(u'\n\n\n')
        # SOURCE LINE 134
        __M_writer(u'\n\n\n\n\n\n\n\n')
        # SOURCE LINE 158
        __M_writer(u'\n\n\n')
        # SOURCE LINE 165
        __M_writer(u'\n\n\n')
        # SOURCE LINE 189
        __M_writer(u'\n\n\n')
        # SOURCE LINE 220
        __M_writer(u'\n\n\n\n  \n')
        # SOURCE LINE 243
        __M_writer(u'\n\n\n')
        # SOURCE LINE 279
        __M_writer(u'\n\n\n')
        # SOURCE LINE 309
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_collectionViewPaper(context,collection):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, u'markup')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'javascriptDefs')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'fileViews')._populate(_import_ns, [u'displayFile', u'displayAudio'])
        _mako_get_namespace(context, u'formViews')._populate(_import_ns, [u'formViewLong', u'formViewForAssociation', u'displayAssociatedFiles', u'formViewForMemory'])
        self = _import_ns.get('self', context.get('self', UNDEFINED))
        def displayCollectionDataAndButtons(collection,displayTitle):
            return render_displayCollectionDataAndButtons(context,collection,displayTitle)
        __M_writer = context.writer()
        # SOURCE LINE 8
        __M_writer(u'\n    ')
        # SOURCE LINE 9

        if collection.elicitor:
            author = collection.elicitor
        else:
            author = collection.enterer
            
        
        # SOURCE LINE 14
        __M_writer(u'\n    <a id="collectiondatabuttonstoggle" class="buttonLink" title="show details about this collection"\n       onclick="addRemoveElement(\'collectiondatabuttons\', \'collectiondatabuttonstoggle\', \'details about this Collection\');">+</a>\n    <br /><br />\n    <div id="collectiondatabuttons" style="display:none;">\n      ')
        # SOURCE LINE 19
        __M_writer(escape(displayCollectionDataAndButtons(collection, True)))
        __M_writer(u'\n    </div><br /><br />\n    \n    <h1 class="centered">')
        # SOURCE LINE 22
        __M_writer(escape(collection.title))
        __M_writer(u'</h1>\n    <p class="centered">')
        # SOURCE LINE 23
        __M_writer(escape(author.firstName))
        __M_writer(u' ')
        __M_writer(escape(author.lastName))
        __M_writer(u'</p>\n    <p class="centered">')
        # SOURCE LINE 24
        __M_writer(escape(collection.datetimeModified.strftime('%b %d, %Y')))
        __M_writer(u'</p>\n')
        # SOURCE LINE 25
        if collection.contents:
            # SOURCE LINE 26
            __M_writer(u'      ')
            __M_writer(escape(self.displayContentMin()))
            __M_writer(u'\n')
            # SOURCE LINE 27
        else:
            # SOURCE LINE 28
            __M_writer(u'      <p>This Collection has no content</p>\n')
            pass
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayCollectionDataAndButtons(context,collection,displayTitle):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, u'markup')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'javascriptDefs')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'fileViews')._populate(_import_ns, [u'displayFile', u'displayAudio'])
        _mako_get_namespace(context, u'formViews')._populate(_import_ns, [u'formViewLong', u'formViewForAssociation', u'displayAssociatedFiles', u'formViewForMemory'])
        def displayCollectionButtons(collection,viewLongButton=False):
            return render_displayCollectionButtons(context,collection,viewLongButton)
        def displayCollectionData(collection,displayTitle):
            return render_displayCollectionData(context,collection,displayTitle)
        __M_writer = context.writer()
        # SOURCE LINE 37
        __M_writer(u'\n    ')
        # SOURCE LINE 38
        __M_writer(escape(displayCollectionData(collection, displayTitle)))
        __M_writer(u'\n    ')
        # SOURCE LINE 39
        __M_writer(escape(displayCollectionButtons(collection)))
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayFormsAsColumns(context,matches,formsDict):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, u'markup')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'javascriptDefs')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'fileViews')._populate(_import_ns, [u'displayFile', u'displayAudio'])
        _mako_get_namespace(context, u'formViews')._populate(_import_ns, [u'formViewLong', u'formViewForAssociation', u'displayAssociatedFiles', u'formViewForMemory'])
        int = _import_ns.get('int', context.get('int', UNDEFINED))
        h = _import_ns.get('h', context.get('h', UNDEFINED))
        KeyError = _import_ns.get('KeyError', context.get('KeyError', UNDEFINED))
        __M_writer = context.writer()
        # SOURCE LINE 225
        __M_writer(u'\n  ')
        # SOURCE LINE 226

        contents = []
        for match in matches:
            try:
                form = formsDict[int(match[1])]
                glosses = []
                for gloss in form.glosses:
                    glossLine = gloss.glossGrammaticality + gloss.gloss
                    glosses.append(glossLine)
                glosses = '; '.join(glosses)
                line = '<tr><td>%s%s</td><td>%s</td></tr>' % (form.grammaticality, h.storageToOutputTranslate(form.transcription), glosses)
                contents.append(line)        
            except KeyError:
                pass
        contents = h.literal('<table class="collectionColumns">' + '\n'.join(contents) + '</table>')
          
        
        # SOURCE LINE 241
        __M_writer(u'\n  ')
        # SOURCE LINE 242
        __M_writer(escape(contents))
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayForm(context,formsDict,formID,displayType='long'):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, u'markup')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'javascriptDefs')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'fileViews')._populate(_import_ns, [u'displayFile', u'displayAudio'])
        _mako_get_namespace(context, u'formViews')._populate(_import_ns, [u'formViewLong', u'formViewForAssociation', u'displayAssociatedFiles', u'formViewForMemory'])
        displayAudio = _import_ns.get('displayAudio', context.get('displayAudio', UNDEFINED))
        int = _import_ns.get('int', context.get('int', UNDEFINED))
        h = _import_ns.get('h', context.get('h', UNDEFINED))
        KeyError = _import_ns.get('KeyError', context.get('KeyError', UNDEFINED))
        url = _import_ns.get('url', context.get('url', UNDEFINED))
        formViewLong = _import_ns.get('formViewLong', context.get('formViewLong', UNDEFINED))
        __M_writer = context.writer()
        # SOURCE LINE 282
        __M_writer(u'\n  ')
        # SOURCE LINE 283

        try:
            form = formsDict[int(formID)]
        except KeyError:
            form = None
          
        
        # SOURCE LINE 288
        __M_writer(u'\n  FORMID:')
        # SOURCE LINE 289
        __M_writer(escape(formID))
        __M_writer(u';\n  <div class="indentedDiv shiftUp">\n')
        # SOURCE LINE 291
        if form:
            # SOURCE LINE 292
            if displayType == 'long':
                # SOURCE LINE 293
                __M_writer(u'         ')
                __M_writer(escape(formViewLong(form)))
                __M_writer(u'\n')
                # SOURCE LINE 294
            else:
                # SOURCE LINE 295
                __M_writer(u'         <span class="emphasize">')
                __M_writer(escape(form.grammaticality))
                __M_writer(escape(h.storageToOutputTranslate(form.transcription)))
                __M_writer(u'</span><br />\n')
                # SOURCE LINE 296
                for gloss in form.glosses:
                    # SOURCE LINE 297
                    __M_writer(u'            &lsquo;')
                    __M_writer(escape(gloss.glossGrammaticality))
                    __M_writer(escape(gloss.gloss))
                    __M_writer(u'&rsquo;<br />\n')
                    pass
                # SOURCE LINE 299
                __M_writer(u'         ')
                OLUFiles = [file for file in form.files if file.utteranceType=='Object Language Utterance'] 
                
                __M_writer(u'\n')
                # SOURCE LINE 300
                for file in OLUFiles:
                    # SOURCE LINE 301
                    __M_writer(u'            ')
                    fileReference = url('retrieve', path=file.name) 
                    
                    __M_writer(u'\n            ')
                    # SOURCE LINE 302
                    displayAudio(file, fileReference) 
                    
                    __M_writer(u'\n')
                    pass
                pass
            # SOURCE LINE 305
        else:
            # SOURCE LINE 306
            __M_writer(u'     There is no Form with ID ')
            __M_writer(escape(formID))
            __M_writer(u'\n')
            pass
        # SOURCE LINE 308
        __M_writer(u'  </div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayCollectionData(context,collection,displayTitle):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, u'markup')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'javascriptDefs')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'fileViews')._populate(_import_ns, [u'displayFile', u'displayAudio'])
        _mako_get_namespace(context, u'formViews')._populate(_import_ns, [u'formViewLong', u'formViewForAssociation', u'displayAssociatedFiles', u'formViewForMemory'])
        __M_writer = context.writer()
        # SOURCE LINE 42
        __M_writer(u'\n  <table class="fileTable">\n    <tr>\n      <td class="fileTableRowLabel">ID</td><td class="dataCell">\n      ')
        # SOURCE LINE 46
        __M_writer(escape(collection.id))
        __M_writer(u'</td>\n    </tr>\n    \n')
        # SOURCE LINE 49
        if displayTitle:
            # SOURCE LINE 50
            __M_writer(u'    <tr>\n      <td class="fileTableRowLabel">title</td><td class="dataCell">\n      ')
            # SOURCE LINE 52
            __M_writer(escape(collection.title))
            __M_writer(u'</td>\n    </tr>\n')
            pass
        # SOURCE LINE 55
        __M_writer(u'    \n    <tr>\n      <td class="fileTableRowLabel">type</td><td class="dataCell">\n      ')
        # SOURCE LINE 58
        __M_writer(escape(collection.type))
        __M_writer(u'</td>\n    </tr>\n    \n')
        # SOURCE LINE 61
        if collection.url:
            # SOURCE LINE 62
            __M_writer(u'    <tr>\n      <td class="fileTableRowLabel">url</td><td class="dataCell">\n      ')
            # SOURCE LINE 64
            __M_writer(escape(collection.url))
            __M_writer(u'</td>\n    </tr>\n')
            pass
        # SOURCE LINE 67
        __M_writer(u'    \n')
        # SOURCE LINE 68
        if collection.description:
            # SOURCE LINE 69
            __M_writer(u'    <tr>\n      <td class="fileTableRowLabel">description</td><td class="dataCell">\n      ')
            # SOURCE LINE 71
            __M_writer(escape(collection.description))
            __M_writer(u'</td>\n    </tr>\n')
            pass
        # SOURCE LINE 74
        __M_writer(u'    \n')
        # SOURCE LINE 75
        if collection.speaker:
            # SOURCE LINE 76
            __M_writer(u'    <tr>\n      <td class="fileTableRowLabel">speaker</td><td class="dataCell">\n      ')
            # SOURCE LINE 78
            __M_writer(escape(collection.speaker.firstName))
            __M_writer(u' ')
            __M_writer(escape(collection.speaker.lastName))
            __M_writer(u'</td>\n    </tr>\n')
            pass
        # SOURCE LINE 81
        __M_writer(u'    \n')
        # SOURCE LINE 82
        if collection.source:
            # SOURCE LINE 83
            __M_writer(u'    <tr>\n      <td class="fileTableRowLabel">source</td><td class="dataCell">\n      ')
            # SOURCE LINE 85
            __M_writer(escape(collection.source.authorFirstName))
            __M_writer(u' ')
            __M_writer(escape(collection.source.authorLastName))
            __M_writer(u' ')
            # SOURCE LINE 86
            __M_writer(u'      (')
            __M_writer(escape(collection.source.year))
            __M_writer(u')</td>\n    </tr>\n')
            pass
        # SOURCE LINE 89
        __M_writer(u'    \n')
        # SOURCE LINE 90
        if collection.elicitor:
            # SOURCE LINE 91
            __M_writer(u'    <tr>\n      <td class="fileTableRowLabel">elicitor</td><td class="dataCell">\n      ')
            # SOURCE LINE 93
            __M_writer(escape(collection.elicitor.firstName))
            __M_writer(u' ')
            __M_writer(escape(collection.elicitor.lastName))
            __M_writer(u'</td>\n    </tr>\n')
            pass
        # SOURCE LINE 96
        __M_writer(u'    \n    <tr>\n      <td class="fileTableRowLabel">enterer</td><td class="dataCell">\n      ')
        # SOURCE LINE 99
        __M_writer(escape(collection.enterer.firstName))
        __M_writer(u' ')
        __M_writer(escape(collection.enterer.lastName))
        __M_writer(u'</td>\n    </tr>\n    \n')
        # SOURCE LINE 102
        if collection.dateElicited:
            # SOURCE LINE 103
            __M_writer(u'    <tr>\n      <td class="fileTableRowLabel">date elicited</td><td class="dataCell">\n      ')
            # SOURCE LINE 105
            __M_writer(escape(collection.dateElicited.strftime('%b %d, %Y')))
            __M_writer(u'</td>\n    </tr>\n')
            pass
        # SOURCE LINE 108
        __M_writer(u'    \n    <tr>\n      <td class="fileTableRowLabel">time entered</td><td class="dataCell">\n      ')
        # SOURCE LINE 111
        __M_writer(escape(collection.datetimeEntered.strftime('%b %d, %Y at %I:%M %p')))
        __M_writer(u'</td>\n    </tr>\n    \n    <tr>\n      <td class="fileTableRowLabel">last updated</td><td class="dataCell">\n      ')
        # SOURCE LINE 116
        __M_writer(escape(collection.datetimeModified.strftime('%b %d, %Y at %I:%M %p')))
        __M_writer(u'</td>\n    </tr>\n    \n  </table>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayContent(context,collection):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, u'markup')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'javascriptDefs')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'fileViews')._populate(_import_ns, [u'displayFile', u'displayAudio'])
        _mako_get_namespace(context, u'formViews')._populate(_import_ns, [u'formViewLong', u'formViewForAssociation', u'displayAssociatedFiles', u'formViewForMemory'])
        capture = _import_ns.get('capture', context.get('capture', UNDEFINED))
        c = _import_ns.get('c', context.get('c', UNDEFINED))
        def displayFormsAsColumns(matches,formsDict):
            return render_displayFormsAsColumns(context,matches,formsDict)
        url = _import_ns.get('url', context.get('url', UNDEFINED))
        h = _import_ns.get('h', context.get('h', UNDEFINED))
        def displayContentEmbedded(contents,matches,formsDict,displayType):
            return render_displayContentEmbedded(context,contents,matches,formsDict,displayType)
        dict = _import_ns.get('dict', context.get('dict', UNDEFINED))
        javascriptDefs = _mako_get_namespace(context, 'javascriptDefs')
        __M_writer = context.writer()
        # SOURCE LINE 192
        __M_writer(u'\n  ')
        # SOURCE LINE 193

        formsDict = dict([(form.id, form) for form in collection.forms])
        # Apply Markdown conversion
        #  contents = h.literal(h.markdown(collection.contents, safe_mode="escape"))
        contents = h.literal(h.rst2html(collection.contents))
        # Replace "form[X]" with a representation of Form X
        patt = re.compile('(form\[([0-9]+)\])')
        matches = patt.findall(contents)
        if c.collectionViewType == 'columns':
            contents = capture(displayFormsAsColumns, matches, formsDict)
        else:
            contents = capture(displayContentEmbedded, contents, matches, formsDict, c.collectionViewType)
        cClass = sClass = lClass = 'buttonLink'
        if c.collectionViewType == 'long':
            lClass += ' selected'
        elif c.collectionViewType == 'short':
            sClass += ' selected'
        else:
            cClass += ' selected'
          
        
        # SOURCE LINE 212
        __M_writer(u'\n  ')
        # SOURCE LINE 213
        __M_writer(escape(javascriptDefs.toggleLabelsJavaScript()))
        __M_writer(u'\n  ')
        # SOURCE LINE 214
        __M_writer(escape(javascriptDefs.labelsHidden()))
        __M_writer(u'\n  <a class="buttonLink" id="toggleRowLabelsButton" title="hide labels">+</a>\n  <a class="')
        # SOURCE LINE 216
        __M_writer(escape(lClass))
        __M_writer(u'" name="long" href="')
        __M_writer(escape(url(controller='collection', action='view', id=collection.id, option='long', anchor='long')))
        __M_writer(u'" title="View Forms embedded in content; show transcription, morpheme break, morpheme gloss and glosses data">long</a>\n  <a class="')
        # SOURCE LINE 217
        __M_writer(escape(sClass))
        __M_writer(u'" name="short" href="')
        __M_writer(escape(url(controller='collection', action='view', id=collection.id, option='short', anchor='short')))
        __M_writer(u'" title="View Forms embedded in content; show only transcription and glosses data">short</a>\n  <a class="')
        # SOURCE LINE 218
        __M_writer(escape(cClass))
        __M_writer(u'" name="columns" href="')
        __M_writer(escape(url(controller='collection', action='view', id=collection.id, option='columns', anchor='columns')))
        __M_writer(u'" title="View Forms and no other content; show transcriptions in left column and glosses in right">columns</a>\n  ')
        # SOURCE LINE 219
        __M_writer(escape(h.literal(contents)))
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayCollectionButtons(context,collection,viewLongButton=False):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, u'markup')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'javascriptDefs')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'fileViews')._populate(_import_ns, [u'displayFile', u'displayAudio'])
        _mako_get_namespace(context, u'formViews')._populate(_import_ns, [u'formViewLong', u'formViewForAssociation', u'displayAssociatedFiles', u'formViewForMemory'])
        url = _import_ns.get('url', context.get('url', UNDEFINED))
        __M_writer = context.writer()
        # SOURCE LINE 123
        __M_writer(u'\n  <div class="fileButtonsDiv">\n')
        # SOURCE LINE 125
        if viewLongButton:
            # SOURCE LINE 126
            __M_writer(u'    <a href="')
            __M_writer(escape(url(controller='collection', action='view', id=collection.id)))
            __M_writer(u'" class="buttonLink" title="View this Collection in greater detail">view</a>\n')
            pass
        # SOURCE LINE 128
        __M_writer(u'    <a href="')
        __M_writer(escape(url(controller='collection', action='update', id=collection.id)))
        __M_writer(u'" class="buttonLink" title="Modify this Collection">update</a>\n    <a href="')
        # SOURCE LINE 129
        __M_writer(escape(url(controller='collection', action='delete', id=collection.id)))
        __M_writer(u'" class="buttonLink" onclick="return confirmDelete(\'Collection\', ')
        __M_writer(escape(collection.id))
        __M_writer(u')" title="Delete this Collection; confirmation will be required">delete</a>\n    <a href="')
        # SOURCE LINE 130
        __M_writer(escape(url(controller='collection', action='associate', id=collection.id)))
        __M_writer(u'" class="buttonLink" title="Associate this Collection to one or more Files">associate</a>\n    <a href="')
        # SOURCE LINE 131
        __M_writer(escape(url(controller='export', action='options', id='collectionforms%s' % collection.id)))
        __M_writer(u'" class="buttonLink" title="Export just the Forms referenced in the content of this Collection">export forms</a>\n    <a href="')
        # SOURCE LINE 132
        __M_writer(escape(url(controller='export', action='options', id='collectioncontent%s' % collection.id)))
        __M_writer(u'" class="buttonLink" title="Export the content of this Collection; referenced Forms will be embedded in the exported file">export content</a>\n  </div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_collectionViewReallyShort(context,collection,displayTitle=True):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, u'markup')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'javascriptDefs')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'fileViews')._populate(_import_ns, [u'displayFile', u'displayAudio'])
        _mako_get_namespace(context, u'formViews')._populate(_import_ns, [u'formViewLong', u'formViewForAssociation', u'displayAssociatedFiles', u'formViewForMemory'])
        url = _import_ns.get('url', context.get('url', UNDEFINED))
        len = _import_ns.get('len', context.get('len', UNDEFINED))
        __M_writer = context.writer()
        # SOURCE LINE 168
        __M_writer(u'\n  ')
        # SOURCE LINE 169

        URL = url(controller='collection', action='view', id=collection.id)
        cTitle = collection.title
        if len(cTitle) > 20:
            cTitle = u'%s...' % cTitle[:20]
          
        
        # SOURCE LINE 174
        __M_writer(u'\n  <tr>\n   <td class="onethirdcell">\n    <a href="')
        # SOURCE LINE 177
        __M_writer(escape(URL))
        __M_writer(u'" title="View this Collection in greater detail">\n    ')
        # SOURCE LINE 178
        __M_writer(escape(cTitle))
        __M_writer(u'</a>\n   </td>\n   <td class="onethirdcell">\n    <a href="')
        # SOURCE LINE 181
        __M_writer(escape(URL))
        __M_writer(u'" title="View this Collection in greater detail">\n    ')
        # SOURCE LINE 182
        __M_writer(escape(collection.datetimeModified.strftime('%b %d, %Y')))
        __M_writer(u'</a>\n   </td>\n   <td class="onethirdcell">\n    <a href="')
        # SOURCE LINE 185
        __M_writer(escape(URL))
        __M_writer(u'" title="View this Collection in greater detail">\n    ')
        # SOURCE LINE 186
        __M_writer(escape(collection.type))
        __M_writer(u'</a>\n   </td>\n  </tr>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayContentMin(context):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, u'markup')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'javascriptDefs')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'fileViews')._populate(_import_ns, [u'displayFile', u'displayAudio'])
        _mako_get_namespace(context, u'formViews')._populate(_import_ns, [u'formViewLong', u'formViewForAssociation', u'displayAssociatedFiles', u'formViewForMemory'])
        h = _import_ns.get('h', context.get('h', UNDEFINED))
        c = _import_ns.get('c', context.get('c', UNDEFINED))
        __M_writer = context.writer()
        # SOURCE LINE 32
        __M_writer(u'\n  ')
        # SOURCE LINE 33
        __M_writer(escape(h.literal(c.contents)))
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_collectionViewLong(context,collection,displayTitle=True):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, u'markup')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'javascriptDefs')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'fileViews')._populate(_import_ns, [u'displayFile', u'displayAudio'])
        _mako_get_namespace(context, u'formViews')._populate(_import_ns, [u'formViewLong', u'formViewForAssociation', u'displayAssociatedFiles', u'formViewForMemory'])
        self = _import_ns.get('self', context.get('self', UNDEFINED))
        displayAssociatedFiles = _import_ns.get('displayAssociatedFiles', context.get('displayAssociatedFiles', UNDEFINED))
        __M_writer = context.writer()
        # SOURCE LINE 142
        __M_writer(u'\n    ')
        # SOURCE LINE 143
        __M_writer(escape(self.displayCollectionData(collection, displayTitle)))
        __M_writer(u'\n    ')
        # SOURCE LINE 144
        __M_writer(escape(self.displayCollectionButtons(collection)))
        __M_writer(u'\n    <div class="tableSpacerDiv"></div>\n')
        # SOURCE LINE 146
        if collection.files:
            # SOURCE LINE 147
            __M_writer(u'      <h1 class="heading">Associated Files</h1><br />\n      ')
            # SOURCE LINE 148
            __M_writer(escape(displayAssociatedFiles(collection, 'collection')))
            __M_writer(u'\n      <div class="tableSpacerDiv"></div>\n')
            pass
        # SOURCE LINE 151
        __M_writer(u'    <h1 class="heading">Content</h1><br />\n')
        # SOURCE LINE 152
        if collection.contents:
            # SOURCE LINE 153
            __M_writer(u'      ')
            __M_writer(escape(self.displayContent(collection)))
            __M_writer(u'\n')
            # SOURCE LINE 154
        else:
            # SOURCE LINE 155
            __M_writer(u'      This Collection has no content\n')
            pass
        # SOURCE LINE 157
        __M_writer(u'    <div class="tableSpacerDiv"></div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_collectionViewShort(context,collection,displayTitle=True):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, u'markup')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'javascriptDefs')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'fileViews')._populate(_import_ns, [u'displayFile', u'displayAudio'])
        _mako_get_namespace(context, u'formViews')._populate(_import_ns, [u'formViewLong', u'formViewForAssociation', u'displayAssociatedFiles', u'formViewForMemory'])
        self = _import_ns.get('self', context.get('self', UNDEFINED))
        __M_writer = context.writer()
        # SOURCE LINE 161
        __M_writer(u'\n    ')
        # SOURCE LINE 162
        __M_writer(escape(self.displayCollectionData(collection, displayTitle)))
        __M_writer(u'\n    ')
        # SOURCE LINE 163
        __M_writer(escape(self.displayCollectionButtons(collection, True)))
        __M_writer(u'\n    <div class="tableSpacerDiv"></div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayContentEmbedded(context,contents,matches,formsDict,displayType):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, u'markup')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'javascriptDefs')._populate(_import_ns, [u'*'])
        _mako_get_namespace(context, u'fileViews')._populate(_import_ns, [u'displayFile', u'displayAudio'])
        _mako_get_namespace(context, u'formViews')._populate(_import_ns, [u'formViewLong', u'formViewForAssociation', u'displayAssociatedFiles', u'formViewForMemory'])
        capture = _import_ns.get('capture', context.get('capture', UNDEFINED))
        def displayForm(formsDict,formID,displayType='long'):
            return render_displayForm(context,formsDict,formID,displayType)
        int = _import_ns.get('int', context.get('int', UNDEFINED))
        h = _import_ns.get('h', context.get('h', UNDEFINED))
        markup = _mako_get_namespace(context, 'markup')
        KeyError = _import_ns.get('KeyError', context.get('KeyError', UNDEFINED))
        url = _import_ns.get('url', context.get('url', UNDEFINED))
        str = _import_ns.get('str', context.get('str', UNDEFINED))
        __M_writer = context.writer()
        # SOURCE LINE 246
        __M_writer(u'\n  ')
        # SOURCE LINE 247

        for match in matches:
            contents = contents.replace(match[0], capture(displayForm, formsDict, match[1], displayType))
        
        # Replace "FORMID:X" with an enumeration signifier, e.g., "(1)"
        patt = re.compile('FORMID:([0-9]+);')
        lines = []
        number = 1
        formIDToNum = {}
        for line in contents.split('\n'):
            if patt.match(line.strip()):
                formID = int(patt.findall(line)[0])
                Url = url(controller='form', action='view', id=formID)
                title = 'Click to view Form %s' % formID
                anchorStart = '<a href="%s" title="%s">' % (Url, title)
                line = '<p>(%s%s</a>)</p>' % (anchorStart, number)
                try:
                    formIDToNum[formID].append(number)
                except KeyError:
                    formIDToNum[formID] = [number]
                number += 1
            lines.append(line)
        contents = '\n'.join(lines)
        patt = re.compile('(ref\[([0-9]+)\])')
        matches = patt.findall(contents)
        for match in matches:
            replacement = ', '.join([str(formID) for formID in formIDToNum[int(match[1])]])
            contents = contents.replace(match[0], replacement)
        contents = capture(markup.linkToOLDEntitites, contents)
        contents = h.literal(contents)
          
        
        # SOURCE LINE 277
        __M_writer(u'\n  ')
        # SOURCE LINE 278
        __M_writer(escape(contents))
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


